﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Services;
using WebApp.Models;
using Models;

namespace WebApp.Controllers
{
    public class HomeController : Controller
    {
        ContentsServices contentSvrs = new ContentsServices();
        CategoryServices categorySvrs = new CategoryServices();
        
        public ActionResult Index()
        {
            IndexViewModels retResult = new IndexViewModels();

            retResult.LastContents = contentSvrs.GetTopList(1, 15);
            retResult.CoverContents = contentSvrs.GetCover(1, 5);
            List<Category> _categoryList = categorySvrs.GetList(t => t.CategoryName != "");
            List<IndexViewModel> _indexModels = new List<IndexViewModel>();
            foreach (var _cate in _categoryList)
            {
                IndexViewModel model = new IndexViewModel();
                model.Category = _cate;
                model.ContentList = contentSvrs.GetListByCategory(_cate.CategoryUrl, 1, 10);

                _indexModels.Add(model);
            }
            retResult.IndexModels = _indexModels;

            return View(retResult);
        }
    }
}
